﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Common.Master" AutoEventWireup="true" CodeBehind="WellCatalogManage.aspx.cs" Inherits="Web.Views.DataManage.WellCatalogManage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
	<title></title>
    <script type="text/javascript" src="../../Javascript/json2.js"></script>
 <%-- <script type="text/javascript">
      var appendMenuList = new Array;
      var editMenuList = new Array;
      var removeMenuList = new Array;
      var status = '';
      $(function () {
          $('#treeArchiveMenu').height($('body').height() - 30);
      });
      $(function () {
          var timestamp = new Date().getTime();
          $('#treeArchiveMenu').tree({
              method: "get",
              lines: true,
              idFiled: "id",
              textFiled: "text",
              parentField: "pid",
              cascadeCheck: false,
              url: "../../HttpHandles/WellCatalogManageHandler.ashx?timestamp=" + new Date().getTime() + "",
              onLoadError: function (node, param) {
                  alert('加载失败！');
              },
              onSelect: function (node) {
                  if (node) {
                      $('#menuText').val(node.text);
                      setRadios(node.attributes.isWellCode);
                      $('#menuTextValidateMsg').hide();
                      $('#radiosValidateMsg').hide();
                      if (node.attributes.isWellCode + '' != '1') {
                          $('#btnAppend').attr('disabled', 'disabled');
                       } else {
                          $('#btnAppend').removeAttr('disabled');
                      }
                      $('#btnRemove').removeAttr('disabled');
                      $('#btnCommit').removeAttr('disabled');
                      $('#btnReject').removeAttr('disabled');
                      status = 'edit';
                  }
              }
          });
      });
      function append() {
          var node = $('#treeArchiveMenu').tree('getSelected');
          if (node == null) {
              alert('请先选择一个节点！');
              return;
          }
          $('#menuText').val('');
          resetRadios();
          $('#btnAppend').attr('disabled', 'disabled');
          $('#btnRemove').attr('disabled', 'disabled');
          $('#btnCommit').attr('disabled', 'disabled');
          $('#btnReject').attr('disabled', 'disabled');
          status = 'append';
      }
      function remove() {
          var node = $('#treeArchiveMenu').tree('getSelected');
          if (node == null) {
              alert('请先选择一个节点！');
              return;
          }
          var children = $('#treeArchiveMenu').tree('getChildren', node.target);
          var isEmpty = "0";
          var postObj = new Object;
          postObj.catalogId = node.id;
          var jsonStr = JSON.stringify(postObj);
          $.ajax({
              type: 'POST',
              contentType: "application/json",
              url: "DataManageServices.asmx/IsEmptyIsThisWellCatalog",
              data: jsonStr,
              dataType: 'json',
              async: false,
              success: function (event, XMLHttpRequest, ajaxOptions) {
                  if (event && event.d == "1") {
                      isEmpty = "1";
                  } else {
                      isEmpty = "0";
                  }
                  return;
              },
              error: function (event, XMLHttpRequest, ajaxOptions, thrownError) {
                  var message = '服务器错误！';
                  response = jQuery.parseJSON(event.responseText);
                  if (response != null) {
                      message += ('</br>' + response.Message)
                  }
                  alert(message);
                  return;
              }
          });
          if (children.length > 0 || isEmpty == "0") {
              alert('此编目下存在子节点或单井数据,请先删除其下的子节点或单井数据！');
              return;
          }
          $('#menuText').val('');
          resetRadios();
          var pid = "0";
          var pnode = $('#treeArchiveMenu').tree('getParent', node.target);
          if (pnode != null) {
              pid = pnode.id;
          }
          $('#treeArchiveMenu').tree('remove', node.target);
          for (i = 0; i < appendMenuList.length; i++) {
              if (appendMenuList[i].WellcatalogId == node.id) {
                  appendMenuList.splice(i, 1);
                  return;
              }
          }
          for (i = 0; i < editMenuList.length; i++) {
              if (editMenuList[i].WellcatalogId == node.id) {
                  editMenuList.splice(i, 1);
                  break;
              }
          }
          
          var menu = new Object;
          menu.WellcatalogId = node.id;
          menu.CatalogDescript = node.text;
          menu.ParentID = pid;
          menu.CatelogSort = node.attributes.catelogSort;
          menu.IsWellCode = node.attributes.isWellCode;
          removeMenuList.push(menu);
          status = '';
          return;
      }
      function commit() {
          var updateModel = new Object;
          updateModel.InsertedRows = appendMenuList;
          updateModel.UpdatedRows = editMenuList;
          updateModel.DeletedRows = removeMenuList;
          var postObj = new Object;
          postObj.updateModel = JSON.stringify(updateModel);
          var jsonStr;
          if (updateModel.InsertedRows.length >= 1 || updateModel.UpdatedRows.length >= 1 || updateModel.DeletedRows.length >= 1) {
              try {
                  jsonStr = JSON.stringify(postObj);
              }
              catch (e) {
                  alert(e.Message);
                  return;
              }
              $.ajax({
                  type: 'POST',
                  contentType: "application/json",
                  url: "DataManageServices.asmx/UpdataWellCatalog",
                  data: jsonStr,
                  dataType: 'json',
                  success: function (event, XMLHttpRequest, ajaxOptions) {
                      appendMenuList.splice(0, appendMenuList.length);
                      editMenuList.splice(0, editMenuList.length);
                      removeMenuList.splice(0, removeMenuList.length);
                      $('#treeArchiveMenu').tree('reload');
                      status = '';
                      alert('更新成功！');
                      return;
                  },
                  error: function (event, XMLHttpRequest, ajaxOptions, thrownError) {
                      var message = '服务器错误！';
                      response = jQuery.parseJSON(event.responseText);
                      if (response != null) {
                          message += ('</br>' + response.Message)
                      }
                      alert(message);
                      return;
                  }
              });
          }
          else {
              alert('没有修改！');
              return;
          }
      }
      function reject() {
          $('#menuText').val('');
          resetRadios();
          appendMenuList.splice(0, appendMenuList.length);
          editMenuList.splice(0, editMenuList.length);
          removeMenuList.splice(0, removeMenuList.length);
          $('#treeArchiveMenu').tree('reload');
          status = '';
      }
      function ok() {
          if (status == 'append') {
              var node = $('#treeArchiveMenu').tree('getSelected');
              if (node == null) {
                  alert('请先选择一个节点！');
                  return;
              }
              if (!validateInput()) {
                  return;
              }
              var menuText = $('#menuText').val();
              var isWell = getIsWellCodeValue();
              var menuCode = Math.random();
              var id = new Date().getTime();
              $('#treeArchiveMenu').tree('append', {
                  parent: (node ? node.target : null),
                  data: [{
                      id: id,
                      text: menuText,
                      attributes: { catelogSort: menuCode, isWellCode: isWell }
                  }]
              });
              var menu = new Object;
              menu.WellcatalogId = id;
              menu.CatalogDescript = menuText;
              menu.ParentID = node.id;
              menu.CatelogSort = menuCode;
              menu.IsWellCode = isWell;
              appendMenuList.push(menu);
              var appendNode = $('#treeArchiveMenu').tree('find', id);
              if (node != null) {
                  $('#treeArchiveMenu').tree('select', appendNode.target);
              }
              return;
          }
          if (status == 'edit') {
              var node = $('#treeArchiveMenu').tree('getSelected');
              if (node == null) {
                  alert('请先选择一个节点！');
                  return;
              }
              if (!validateInput()) {
                  return;
              }
              var menuText = $('#menuText').val();
              var menuCode = node.attributes.catelogSort;
              var isWell = getIsWellCodeValue();
              node.text = menuText;
              node.attributes.isWellCode = isWell;
              $('#treeArchiveMenu').tree('update', node);
              for (i = 0; i < appendMenuList.length; i++) {
                  if (appendMenuList[i].WellcatalogId == node.id) {
                      appendMenuList[i].CatalogDescript = menuText;
                      appendMenuList[i].CatelogSort = menuCode;
                      appendMenuList[i].IsWellCode = isWell;
                      return;
                  }
              }
              for (i = 0; i < editMenuList.length; i++) {
                  if (editMenuList[i].WellcatalogId == node.id) {
                      editMenuList[i].CatalogDescript = menuText;
                      editMenuList[i].CatelogSort = menuCode;
                      editMenuList[i].IsWellCode = isWell;
                      return;
                  }
              }
              var pid = "0";
              var pnode = $('#treeArchiveMenu').tree('getParent', node.target);
              if (pnode != null) {
                  pid = pnode.id;
              }
              var menu = new Object;
              menu.WellcatalogId = node.id;
              menu.CatalogDescript = menuText;
              menu.ParentID = pid;
              menu.CatelogSort = menuCode;
              menu.IsWellCode = isWell;
              editMenuList.push(menu);
              return;
          }
      }
      function cancel() {
          var node = $('#treeArchiveMenu').tree('getSelected');
          if (node) {
              $('#menuText').val(node.text);
              setRadios(node.attributes.isWellCode);
          }
          else {
              $('#menuText').val('');
              resetRadios(); 
          }
          $('#menuTextValidateMsg').hide();
          $('#radiosValidateMsg').hide();
          $('#btnAppend').removeAttr('disabled');
          $('#btnRemove').removeAttr('disabled');
          $('#btnCommit').removeAttr('disabled');
          $('#btnReject').removeAttr('disabled');
          status = '';
      }
      function validateInput() {
          var validateResult = true;
          var menuText = $('#menuText').val();
          var isWell = getIsWellCodeValue();
          if (menuText == null || menuText == '') {
              $('#menuTextValidateMsg').show();
              validateResult = false;
          }
          if (isWell == null) {
              $('#radiosValidateMsg').show();
              validateResult = false;
          }
          if (!validateResult) {
              return false;
          }
          $('#menuTextValidateMsg').hide();
          $('#radiosValidateMsg').hide();
          return true;
      }
      function moveUp() {
          var node = $('#treeArchiveMenu').tree('getSelected');
          if (node == null) {
              alert('请先选择一个节点！');
              return;
          }
          var pnode = $('#treeArchiveMenu').tree('getParent', node.target);
          if (pnode != null) {
              var ppnode = $('#treeArchiveMenu').tree('getParent', pnode.target);
              var popNode = $('#treeArchiveMenu').tree('pop', node.target);
              $('#treeArchiveMenu').tree('append', { parent: ppnode ? ppnode.target : null, data: popNode });
          }
      }

      function getIsWellCodeValue() {
          if ($('#RadioA').attr('checked') == false && $('#RadioB').attr('checked') == false) {
              return null;
          }
          if ($('#RadioA').attr('checked') == true) {
              return 1;
          }
          if ($('#RadioB').attr('checked') == true) {
              return 0;
          }
      }

      function setRadios(value) {
          if (value + '' == '1') {
              $('#RadioB').attr('checked', false);
              $('#RadioA').attr('checked', true);
          }
          else if (value + '' == '0') {
              $('#RadioA').attr('checked', false);
              $('#RadioB').attr('checked', true);
          }
          else {
              resetRadios();
          }
      }

      function resetRadios(){
          $('#RadioB').attr('checked', false);
          $('#RadioA').attr('checked', false);
      }

      function onRadioASelect() {
          $('#RadioB').attr('checked', false);
          $('#RadioA').attr('checked', true);
      }

      function onRadioBSelect() {
          $('#RadioA').attr('checked', false);
          $('#RadioB').attr('checked', true);
      }
  </script>--%>

    <link href="../../zTree3.4/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
    <script src="../../zTree3.4/jquery.ztree.all-3.4.js" type="text/javascript"></script>
    
    <style type="text/css">
        .ztree li span.button.firstPage { margin-left:2px; margin-right: 0; background-position:-144px -16px; vertical-align:top; vertical-align:middle;}
        .ztree li span.button.prevPage { margin-left:2px; margin-right: 0; background-position:-144px -48px; vertical-align:top; vertical-align:middle;}
        .ztree li span.button.nextPage { margin-left:2px; margin-right: 0; background-position:-144px -64px; vertical-align:top; vertical-align:middle;}
        .ztree li span.button.lastPage { margin-left:2px; margin-right: 0; background-position:-144px -32px; vertical-align:top; vertical-align:middle;}
        .ztree li span.button.add {margin-left:1px; margin-right: 0px; background-position:-144px 0; vertical-align:top; vertical-align:middle;}
        .ztree li span.button.reload {margin-left:1px; margin-right: 0px; vertical-align:top; vertical-align:middle; background-position: 0px 0px; background-image:url("../../Easy_UI/themes/icons/reload.png");}
        .ztree li span.button.search {margin-left:1px; margin-right: 0px; margin-bottom:1px; vertical-align:middle; vertical-align:middle; background-position: 0px 0px; background-image:url("../../Easy_UI/themes/icons/search.png");}
        .searchSpanInSearchBox{margin-left:1px; margin-right: 0px; width:16px; height:16px;display: inline-block; cursor: pointer; vertical-align:25%; background-position: 0px 0px; background-image:url("../../Easy_UI/themes/icons/search.png");}
        .cancelSpanInSearchBox{margin-left:2px; margin-right: 0px; width:16px; height:16px;display: inline-block; cursor: pointer; vertical-align:25%; background-position: 0px 0px; background-image:url("../../Easy_UI/themes/default/images/tree_dnd_no.png");}
        .demoFirstPageButtonStyle{line-height:0; margin:0; width:16px; height:16px; display: inline-block; vertical-align:middle;
	                     border:0 none; cursor: pointer;outline:none;
	                     background-color:transparent; background-repeat:no-repeat; background-attachment: scroll;
	                     background-image:url("../../zTree3.4/css/zTreeStyle/img/zTreeStandard.png");
	                     margin-left:2px; margin-right: 0; background-position:-144px -16px; vertical-align:top;}
	    .demoPrevPageButtonStyle{line-height:0; margin:0; width:16px; height:16px; display: inline-block; vertical-align:middle;
	                     border:0 none; cursor: pointer;outline:none;
	                     background-color:transparent; background-repeat:no-repeat; background-attachment: scroll;
	                     background-image:url("../../zTree3.4/css/zTreeStyle/img/zTreeStandard.png");
	                     margin-left:2px; margin-right: 0; background-position:-144px -48px; vertical-align:top;}
	    .demoNextPageButtonStyle{line-height:0; margin:0; width:16px; height:16px; display: inline-block; vertical-align:middle;
	                     border:0 none; cursor: pointer;outline:none;
	                     background-color:transparent; background-repeat:no-repeat; background-attachment: scroll;
	                     background-image:url("../../zTree3.4/css/zTreeStyle/img/zTreeStandard.png");
	                     margin-left:2px; margin-right: 0; background-position:-144px -64px; vertical-align:top;}
	     .demoLastPageButtonStyle{line-height:0; margin:0; width:16px; height:16px; display: inline-block; vertical-align:middle;
	                     border:0 none; cursor: pointer;outline:none;
	                     background-color:transparent; background-repeat:no-repeat; background-attachment: scroll;
	                     background-image:url("../../zTree3.4/css/zTreeStyle/img/zTreeStandard.png");
	                     margin-left:2px; margin-right: 0; background-position:-144px -32px; vertical-align:top;}
	     .divOverlay { position:absolute; left: 0px; top: 0px; z-index:99999; opacity: 0.3; filter:Alpha(Opacity=30)/*{opacityOverlay}*/; 
	                   background-image: url("../../Styles/base/images/ui-bg_flat_0_aaaaaa_40x100.png"); display:none;}
	     .divOverlay2 { position:absolute; left: 0px; top: 0px; z-index:9999999; opacity: 0.3; filter:Alpha(Opacity=30)/*{opacityOverlay}*/; 
	                   background-image: url("../../Images/OcsState/resources/images/default/shared/blue-loading.gif"); background-repeat: no-repeat; display:none;}
	</style>
    
    <script type="text/javascript">
        window.onerror = function (msg, url, line) {
            alert(msg);
            return true;
        };
        var pageSize = 5;
        var isPage = false;
        var setting = {
            async: {
                enable: true,
                url: getUrl
            },
            check: {
                enable: false
            },
            edit: {
                drag: {
                    autoExpandTrigger: true,
                    prev: false,
                    inner: dropInner,
                    next: false,
                    isCopy: false,
                    autoOpenTime: 99999999
                },
                enable: true,
                showRemoveBtn: false,
                showRenameBtn: false
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            view: {
                addHoverDom: addHoverDom,
                removeHoverDom: removeHoverDom,
                selectedMulti: false
            },
            callback: {
                beforeExpand: beforeExpand,
                onAsyncSuccess: onAsyncSuccess,
                onAsyncError: onAsyncError,
                beforeDrop: zTreeBeforeDrop,
                beforeDragOpen: function (treeId, treeNode) {
                    return false;
                },
                beforeClick: function (treeId, treeNode, clickFlag) {
                    var zTree = $.fn.zTree.getZTreeObj("treeContainer");
                    var nodes = zTree.getSelectedNodes();
                    if (nodes != null && nodes.length > 0) {
                        if (treeNode != nodes[0]) {
                            $("#searchBox").hide();
                        }
                    }
                }
            }
        };
        $(document).ready(function () {
            $.fn.zTree.init($('#treeContainer'), setting, null);
            $(window).resize(function () {
                var divOverlay = $('#divOverlay');
                var divOverlay2 = $('#divOverlay2');
                var overlayHeight = Math.max($(document.body).attr('scrollHeight'), $(document.body).height());
                var overlayWidth = Math.max($(document.body).attr('scrollWidth'), $(document.body).width());
                if (divOverlay != null && divOverlay.length > 0) {
                    if (divOverlay.css('display') != 'none') {

                        divOverlay.css({ width: 0, height: 0 }).css({ width: overlayWidth, height: overlayHeight });
                    }
                }
                if (divOverlay2 != null && divOverlay2.length > 0) {
                    if (divOverlay2.css('display') != 'none') {
                        divOverlay2.css({ width: 0, height: 0 }).css({ width: overlayWidth, height: overlayHeight });
                    }
                }
            });
        });
        function getUrl(treeId, treeNode) {
            var param = '';
            if (treeNode == null) {
                param = "?treeType=singlewelltree&id=" + (-1) + "&page=" + 1 + "&pageSize=" + pageSize+"&isPage="+isPage+"&searchLevel="+"1"+"&searchParam="+"";
            }
            else {
                var searchLevel = treeNode.searchLevel != null ? treeNode.searchLevel:"1";
                var searchParam = treeNode.searchParam != null ? treeNode.searchParam : "";
                param = "?treeType=singlewelltree&id=" + treeNode.id + "&page=" + treeNode.page + "&pageSize=" + treeNode.pageSize + "&isPage=" + isPage+"&searchLevel="+searchLevel+"&searchParam="+encodeURIComponent(searchParam);
            }
            return "../../HttpHandles/GetTreeDataHandler.ashx" + param + "&timestamp=" + new Date().getTime() + "";
        }
        function dropInner(treeId, nodes, targetNode) {
            if (targetNode == null || targetNode.iswellcode != 1) {
                return false;
            }
            return true;
        }
        function zTreeBeforeDrop(treeId, treeNodes, targetNode, moveType) {
            if (targetNode == null || targetNode.iswellcode != 1 || treeNodes.length == 0) {
                return false;
            }
            var canMove = confirm("确定要移动节点?");
            if (!canMove) {
                return false;
            }
            var zTree = $.fn.zTree.getZTreeObj("treeContainer");
            if (!(isPage && targetNode.count + 1 > pageSize)) {
                zTree.expandNode(targetNode, true, false, false, true);
            }
            var flag = false;
            var firstNode = treeNodes[0];
            var newNodeData = { WellcatalogId: firstNode.id, CatalogDescript: firstNode.name, ParentID: targetNode.id, CatelogSort: firstNode.catelogsort, IsWellCode: firstNode.iswellcode };
            var appendNodes = new Array;
            var editNodes = new Array;
            var removeNodes = new Array;
            editNodes.push(newNodeData);
            var updateModel = new Object;
            updateModel.InsertedRows = appendNodes;
            updateModel.UpdatedRows = editNodes;
            updateModel.DeletedRows = removeNodes;
            try {
                ajaxCommitChanges(updateModel, $("#" + targetNode.tId + "_span").offset(),false, function (isError, data) {
                    if (isError) {
                        alert("移动失败(" + data + ")");
                        flag = false;
                    }
                    else {
                        targetNode.count = targetNode.count + 1;
                        zTree.updateNode(targetNode, false);
                        if (isPage && targetNode.count > pageSize) {
                            goPage(targetNode, 1);
                        }
                        alert("移动成功");
                        flag = true;
                    }
                });
            }
            catch (e) {
                alert("移动失败(" + e.Message + ")");
                flag = false;
            }
            return flag;
        }
        function addDiyDom(treeId, treeNode) {
            if (treeNode == null || treeNode.count == null || treeNode.count <= pageSize || $("#firstBtn_" + treeNode.id).length > 0 || $("#prevBtn_" + treeNode.id).length > 0 || $("#nextBtn_" + treeNode.id).length > 0 || $("#lastBtn_" + treeNode.id).length > 0) {
                return;
            }
            treeNode.maxPage = Math.round(treeNode.count / treeNode.pageSize - .5) + (treeNode.count % treeNode.pageSize == 0 ? 0 : 1);
            var aObj = $("#" + treeNode.tId + "_a");
            aObj.attr("title", "当前第 " + treeNode.page + " 页 / 共 " + treeNode.maxPage + " 页");
            var addStr = "<span class='button firstPage' id='firstBtn_" + treeNode.id
				+ "' title='首页' onfocus='this.blur();'></span><span class='button prevPage' id='prevBtn_" + treeNode.id
				+ "' title='上一页' onfocus='this.blur();'></span><span class='button nextPage' id='nextBtn_" + treeNode.id
				+ "' title='下一页' onfocus='this.blur();'></span><span class='button lastPage' id='lastBtn_" + treeNode.id
				+ "' title='末页' onfocus='this.blur();'></span>";
            aObj.after(addStr);
            var first = $("#firstBtn_" + treeNode.id);
            var prev = $("#prevBtn_" + treeNode.id);
            var next = $("#nextBtn_" + treeNode.id);
            var last = $("#lastBtn_" + treeNode.id);
            first.bind("click", function () {
                if (!treeNode.isAjaxing) {
                    if (treeNode.page != 1) {
                        goPage(treeNode, 1);
                    }
                }
            });
            last.bind("click", function () {
                if (!treeNode.isAjaxing) {
                    if (treeNode.page != treeNode.maxPage) {
                        goPage(treeNode, treeNode.maxPage);
                    }
                }
            });
            prev.bind("click", function () {
                if (!treeNode.isAjaxing) {
                    if (treeNode.page != 1) {
                        goPage(treeNode, treeNode.page - 1);
                    }
                }
            });
            next.bind("click", function () {
                if (!treeNode.isAjaxing) {
                    if (treeNode.page != treeNode.maxPage) {
                        goPage(treeNode, treeNode.page + 1);
                    }
                }
            });
        };
        function addHoverDom(treeId, treeNode) {
            if (isPage) {
                addDiyDom(treeId, treeNode);
            }
            var sObj = $("#" + treeNode.tId + "_span");
            if (treeNode.editNameFlag || $("#editBtn_" + treeNode.id).length > 0 || $("#addBtn_" + treeNode.id).length > 0 || $("#removeBtn_" + treeNode.id).length > 0 || $("#reloadBtn_" + treeNode.id).length > 0 || $("#searchBtn_" + treeNode.id).length > 0) return;
            var opStr = "<span class='button edit' id='editBtn_" + treeNode.id
				+ "' title='编辑' onfocus='this.blur();'></span>";
            if (showRemoveBtn(treeId, treeNode)) {
                opStr += "<span class='button remove' id='removeBtn_" + treeNode.id
				+ "' title='删除' onfocus='this.blur();'></span>";
            }
            else { }
            if (showAddBtn(treeId, treeNode)) {
                opStr += "<span class='button add' id='addBtn_" + treeNode.id
				+ "' title='添加' onfocus='this.blur();'></span>";
            }
            else { }
            if (treeNode.count > 0) {
                opStr += "<span class='button reload' id='reloadBtn_" + treeNode.id
				+ "' title='刷新' onfocus='this.blur();'></span>";
                opStr += "<span class='button search' id='searchBtn_" + treeNode.id
				+ "' title='搜索' onfocus='this.blur();'></span>";
            }
            sObj.after(opStr);
            var btnReload = $("#reloadBtn_" + treeNode.id);
            var btnAdd = $("#addBtn_" + treeNode.id);
            var btnEdit = $("#editBtn_" + treeNode.id);
            var btnRemove = $("#removeBtn_" + treeNode.id);
            var btnSearch = $("#searchBtn_" + treeNode.id);
            if (btnSearch) btnSearch.bind("click", function () {
                offset = $(btnSearch).offset();
                $("#searchBox").css('left', offset.left);
                $("#searchBox").css('top', offset.top);
                $("#searchBox").show();
                $("#searchBox_search").unbind("click");
                $("#searchBox_search").bind("click", function () {
                    var searchTextVal = $("#searchText").val();
                    if ($.trim(searchTextVal) == "") {
                        alert("搜索条件不能为空");
                        return;
                    }
                    var searchLevelVal = $("#selectLevel").val();
                    var searchParamVal = '';
                    if ($("#selectWhere").val() == "allName") {
                        searchParamVal = " = '" + searchTextVal + "' ";
                    }
                    else {
                        searchParamVal = " like '%" + searchTextVal + "%' ";
                    }
                    search(treeNode, searchLevelVal, searchParamVal);
                    treeNode.icon = "../../Easy_UI/themes/icons/search.png";
                });
            });
            if (btnReload) btnReload.bind("click", function () {
                treeNode.searchLevel = "1";
                treeNode.searchParam = "";
                goPage(treeNode, 1);
                treeNode.icon = "";
            });
            if (btnAdd) btnAdd.bind("click", function ( ) {
                offset = $(btnAdd).offset();
                showEditorPanel(offset.left, offset.top, treeId,treeNode, false);
            });
            if (btnEdit) btnEdit.bind("click", function ( ) {
                var zTree = $.fn.zTree.getZTreeObj("treeContainer");
                offset = $(btnEdit).offset();
                showEditorPanel(offset.left, offset.top,treeId, treeNode,true);
             });
             if (btnRemove) btnRemove.bind("click", function () {
                 var canRemove;
                 if (treeNode.count > 0 || treeNode.wellCount > 0) {
                     canRemove = confirm("当前节点下存在子节点或单井数据，删除该节点将删除该节点下的所有数据，确定要删除?");
                 }
                 else {
                     canRemove = confirm("确定要删除?");
                 }
                 if (!canRemove) {
                     return;
                 }
                 var newNodeData = { WellcatalogId: treeNode.id, CatalogDescript: treeNode.name, ParentID: treeNode.pId, CatelogSort: treeNode.catelogsort, IsWellCode: treeNode.iswellcode };
                 var appendNodes = new Array;
                 var editNodes = new Array;
                 var removeNodes = new Array;
                 removeNodes.push(newNodeData);
                 var updateModel = new Object;
                 updateModel.InsertedRows = appendNodes;
                 updateModel.UpdatedRows = editNodes;
                 updateModel.DeletedRows = removeNodes;
                 try {
                     ajaxCommitChanges(updateModel, $(btnRemove).offset(), true,function (isError, data) {
                         if (isError) {
                             alert("删除失败(" + data + ")");
                             return;
                         }
                         else {
                             var zTree = $.fn.zTree.getZTreeObj("treeContainer");
                             var pnode = treeNode.getParentNode();
                             pnode.count = pnode.count - 1;
                             zTree.updateNode(pnode, false);
                             if (isPage && pnode.count + 1 > pageSize) {
                                 goPage(pnode, 1);
                             }
                             else {
                                 zTree.removeNode(treeNode, false);
                             }
                             alert("删除成功");
                         }
                     });
                 }
                 catch (e) {
                     alert("删除失败(" + e.Message + ")");
                     return;
                 }
             });
        };
        function removeHoverDom(treeId, treeNode) {
            $("#searchBtn_" + treeNode.id).unbind().remove();
            $("#reloadBtn_" + treeNode.id).unbind().remove();
            $("#addBtn_" + treeNode.id).unbind().remove();
            $("#removeBtn_" + treeNode.id).unbind().remove();
            $("#editBtn_" + treeNode.id).unbind().remove();
            $("#firstBtn_" + treeNode.id).unbind().remove();
            $("#prevBtn_" + treeNode.id).unbind().remove();
            $("#nextBtn_" + treeNode.id).unbind().remove();
            $("#lastBtn_" + treeNode.id).unbind().remove();
        };
        function goPage(treeNode, page) {
            treeNode.page = page;
            if (treeNode.page < 1) treeNode.page = 1;
            if (treeNode.page > treeNode.maxPage) treeNode.page = treeNode.maxPage;
            var zTree = $.fn.zTree.getZTreeObj("treeContainer");
            zTree.reAsyncChildNodes(treeNode, "refresh");
        }
        function beforeExpand(treeId, treeNode) {
            if (treeNode.page == null || treeNode.page < 1) {
                treeNode.page = 1;
            }
            if (treeNode.searchLevel == null) {
                treeNode.searchLevel = "1";
            }
            if (treeNode.searchParam == null) {
                treeNode.searchParam = "";
            }
            return !treeNode.isAjaxing;
        }
        function onAsyncSuccess(event, treeId, treeNode, msg) {
            //if (treeNode == null) {
            //    var zTree = $.fn.zTree.getZTreeObj("treeContainer");
            //    var nodes = zTree.getNodes();
            //    if (nodes != null && nodes.length > 0) {
            //      var rootNode = nodes[0];
            //        if (rootNode != null && rootNode.isParent == true) {
            //            zTree.expandNode(rootNode, true, false, false, true);
            //        }
            //    }
            //}
        }
        function onAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
            var zTree = $.fn.zTree.getZTreeObj("treeContainer");
            alert("异步获取数据出现异常。");
            if (treeNode != null) {
                treeNode.icon = "";
                zTree.updateNode(treeNode);
            }
        }
        function showRemoveBtn(treeId, treeNode) {
            return true;
            if (treeNode.count > 0 || treeNode.wellCount > 0) {
                return false;
            }
            else {
                return true;
            }
        }
        function showEditBtn(treeId, treeNode) {
            return true;
        }
        function showAddBtn(treeId, treeNode) {
            if (treeNode.iswellcode != 1) {
                return false;
            }
            else {
                return true;
            }
        }
        function showEditorPanel(left, top, treeId,treeNode, isEdit) {
            $('#dataEditor_textValidateMsg').hide();
            $('#dataEditor_radiosValidateMsg').hide();
            resetRadios();
            $('#dataEditor_text').val('');
            $('#dataEditor').hide();
            $('#divOverlay').hide();
            var overlayHeight = Math.max($(document.body).attr('scrollHeight'),$(document.body).height()); 
            var overlayWidth = Math.max($(document.body).attr('scrollWidth'), $(document.body).width());
            $('#divOverlay').height(overlayHeight);
            $('#divOverlay').width(overlayWidth);
            $('#divOverlay').show();
            $('#dataEditor').css('left', left);
            $('#dataEditor').css('top', top);
            $('#dataEditor').show();
            if (isEdit) {
                $('#dataEditor_text').val(treeNode.name);
                setRadios(treeNode.iswellcode);
                $("#dataEditor_btnOK").unbind("click");
                $("#dataEditor_btnOK").bind("click", function () {
                    var newName = $('#dataEditor_text').val();
                    var isWellcode = getIsWellCodeValue();
                    var flag = false;
                    if ($.trim(newName) == '') {
                        $('#dataEditor_textValidateMsg').show();
                        flag = true;
                    }
                    if (isWellcode == null) {
                        $('#dataEditor_radiosValidateMsg').show();
                        flag = true;
                    }
                    if (flag) {
                        return;
                    }
                    var newNodeData = { WellcatalogId: treeNode.id, CatalogDescript: newName, ParentID: treeNode.pId, CatelogSort: treeNode.catelogsort, IsWellCode: isWellcode };
                    var appendNodes = new Array;
                    var editNodes = new Array;
                    var removeNodes = new Array;
                    editNodes.push(newNodeData);
                    var updateModel = new Object;
                    updateModel.InsertedRows = appendNodes;
                    updateModel.UpdatedRows = editNodes;
                    updateModel.DeletedRows = removeNodes;
                    try {
                        ajaxCommitChanges(updateModel, $("#dataEditor_btnOK").offset(),true, function (isError, data) {
                            if (isError) {
                                alert("更新失败(" + data + ")");
                                return;
                            }
                            else {
                                treeNode.name = newName;
                                treeNode.iswellcode = isWellcode;
                                var zTree = $.fn.zTree.getZTreeObj("treeContainer");
                                zTree.updateNode(treeNode, false);
                                alert("更新成功");
                                removeHoverDom(treeId, treeNode);
                                addHoverDom(treeId, treeNode);
                                resetRadios();
                                $('#dataEditor_text').val('');
                                $('#dataEditor').hide();
                                $('#divOverlay').hide();
                                $('#dataEditor_textValidateMsg').hide();
                                $('#dataEditor_radiosValidateMsg').hide();
                            }
                        });
                    }
                    catch (e) {
                        alert("更新失败(" + e.Message + ")");
                        return;
                    }
                });
            }
            else {
                resetRadios();
                $('#dataEditor_text').val('');
                $("#dataEditor_btnOK").unbind("click");
                $("#dataEditor_btnOK").bind("click", function () {
                    var addName = $('#dataEditor_text').val();
                    var isWellcode = getIsWellCodeValue();
                    var flag = false;
                    if ($.trim(addName) == '') {
                        $('#dataEditor_textValidateMsg').show();
                        flag = true;
                    }
                    if (isWellcode == null) {
                        $('#dataEditor_radiosValidateMsg').show();
                        flag = true;
                    }
                    if (flag) {
                        return;
                    }
                    var addNodeData = { WellcatalogId: "", CatalogDescript: addName, ParentID: treeNode.id, CatelogSort: " ", IsWellCode: isWellcode };
                    var addNode = { id: "", name: addName, pId: treeNode.id, catelogsort: " ", iswellcode: isWellcode, count: 0, page: 1, pageSize: pageSize, isParent: false, open: false, wellCount: 0 };
                    var appendNodes = new Array;
                    var editNodes = new Array;
                    var removeNodes = new Array;
                    appendNodes.push(addNodeData);
                    var updateModel = new Object;
                    updateModel.InsertedRows = appendNodes;
                    updateModel.UpdatedRows = editNodes;
                    updateModel.DeletedRows = removeNodes;
                    try {
                        var dataIds = ajaxCommitChanges(updateModel, $("#dataEditor_btnOK").offset(),true, function (isError, data) {
                            if (isError) {
                                alert("添加失败(" + data + ")");
                                return;
                            }
                            else {
                                var zTree = $.fn.zTree.getZTreeObj("treeContainer");
                                treeNode.count = treeNode.count + 1;
                                zTree.updateNode(treeNode, false);
                                if (isPage && treeNode.count > pageSize) {
                                    goPage(treeNode, 1);
                                }
                                else {
                                    if (!treeNode.isParent || (treeNode.children != null && treeNode.children.length > 0)) {
                                        addNode.id = data[0];
                                        zTree.addNodes(treeNode, addNode, false);
                                    }
                                    zTree.expandNode(treeNode, true, false, false, true);
                                    var selectNodes = zTree.getNodesByParam("id", addNode.id, treeNode);
                                    zTree.selectNode(selectNodes[0],false);
                                }
                                alert("添加成功");
                                resetRadios();
                                $('#dataEditor_text').val('');
                                $('#dataEditor').hide();
                                $('#divOverlay').hide();
                                $('#dataEditor_textValidateMsg').hide();
                                $('#dataEditor_radiosValidateMsg').hide();
                            }
                        });
                    }
                    catch (e) {
                        alert("添加失败(" + e.Message + ")");
                        return;
                    }
                });
            }
        }
        var error = false;
        var ajaxResponseData = null;
        function ajaxCommitChanges(updateModel, offset, isAsync,callBack) {
            try {
                var postObj = new Object;
                postObj.updateModel = JSON.stringify(updateModel);
                var jsonStr;
                jsonStr = JSON.stringify(postObj);
                $.ajax({
                    type: 'POST',
                    contentType: "application/json",
                    url: "DataManageServices.asmx/UpdataWellCatalog",
                    data: jsonStr,
                    dataType: 'json',
                    async: isAsync,
                    success: function (event, XMLHttpRequest, ajaxOptions) {
                        var response = jQuery.parseJSON(event.d);
                        callBack(false, response.DataIds);
                    },
                    error: function (event, XMLHttpRequest, ajaxOptions, thrownError) {
                        var message = "服务器错误";
                        var response = jQuery.parseJSON(event.responseText);
                        if (response != null) {
                            message += (":" + response.Message);
                        }
                        message += "!";
                        callBack(true, message);
                    },
                    beforeSend: function (jqXHR, settings) {
                        var overlayHeight = Math.max($(document.body).attr('scrollHeight'), $(document.body).height());
                        var overlayWidth = Math.max($(document.body).attr('scrollWidth'), $(document.body).width());
                        $('#divOverlay2').height(overlayHeight);
                        $('#divOverlay2').width(overlayWidth);
                        $('#divOverlay2').css("backgroundPosition", offset.left + "px " + offset.top + "px");
                        $("#divOverlay2").show();
                    },
                    complete: function (jqXHR, textStatus) {
                        $("#divOverlay2").hide();
                    }
                });
            }
            catch (e) {
                throw (e);
            }
        }
        function resetRadios() {
            $('#dataEditor_radioB').attr('checked', true);
            $('#dataEditor_radioA').attr('checked', false);
        }
        function dataEditor_radioA_click() {
            $('#dataEditor_radioB').attr('checked', false);
            $('#dataEditor_radioA').attr('checked', true);
        }
        function dataEditor_radioB_click() {
            $('#dataEditor_radioA').attr('checked', false);
            $('#dataEditor_radioB').attr('checked', true);
        }
        function setRadios(value) {
            if (value  == 1) {
                $('#dataEditor_radioB').attr('checked', false);
                $('#dataEditor_radioA').attr('checked', true);
            }
            else{
                $('#dataEditor_radioA').attr('checked', false);
                $('#dataEditor_radioB').attr('checked', true);
            }
        }
        function getIsWellCodeValue() {
            if ($('#dataEditor_radioA').attr('checked') == false && $('#dataEditor_radioB').attr('checked') == false) {
                return null;
            }
            if ($('#dataEditor_radioA').attr('checked') == true) {
                return 1;
            }
            if ($('#dataEditor_radioB').attr('checked') == true) {
                return 0;
            }
        }
        function dataEditor_cancel_click() {
            $('#dataEditor_textValidateMsg').hide();
            $('#dataEditor_radiosValidateMsg').hide();
            resetRadios();
            $('#dataEditor_text').val('');
            $('#dataEditor').hide();
            $('#divOverlay').hide();
        }
        var logArray = new Array;
        function log(treeId,oldNodeData,currentNodeData,oldPnodeData,currentPnodeData,opType) {
            if (opType == "move") {

            }
            else if (opType == "add") {

            }
            else if (opType == "edit") {

            }
            else if (opType == "remove") {

            }
            else {
                return;
            }
        }

        function searchBox_cancel_click() {
            $("#searchBox").hide();
        }

        function search(treeNode, searchLevel, searchParam) {
            if (treeNode != null) {
                var zTree = $.fn.zTree.getZTreeObj("treeContainer");
                treeNode.searchLevel = searchLevel;
                treeNode.searchParam = searchParam;
                zTree.reAsyncChildNodes(treeNode, "refresh");
            }
        }
    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <%--<div style="width:300px;height:auto;overflow:auto;position:relative;left:15px;top:15px;float:left;">
        <ul id="treeArchiveMenu"></ul>
    </div>
    <div style="position:relative;left:100px;top:100px;width:600px;">
        <button type="button" id="btnAppend" class="sexybutton" onclick="append();"><span><span><span class="add">新增</span></span></span></button> 
        <button type="button" id="btnRemove" class="sexybutton" onclick="remove();"><span><span><span class="delete">移除</span></span></span></button> 
        <button type="button" id="btnMoveUp" class="sexybutton" onclick="moveUp();" style=" display:none;"><span><span><span class="save">上移</span></span></span></button>  
        <button type="button" id="btnCommit" class="sexybutton" onclick="commit();"><span><span><span class="save">提交</span></span></span></button>  
        <button type="button" id="btnReject" class="sexybutton" onclick="reject();"><span><span><span class="export">撤销</span></span></span></button><br/>
        <span>编目名称（必填）：</span> 
        <input id="menuText"/>
        <span style="color:Red;">*</span><span id="menuTextValidateMsg" style="color:Red;display:none;">必须填写编目名称</span><br/>
        <span>是否允许创建子编目（必填）：</span>
        <input type="radio" id="RadioA" value="1" onclick="onRadioASelect();"/><span>是</span>
        <input type="radio" id="RadioB" value="0" onclick="onRadioBSelect();" /><span>否</span>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:Red;">*</span><span id="radiosValidateMsg" style="color:Red;display:none;">必须选择是否允许创建子编目</span><br/>
        <button type="button" id="btnOK" class="sexybutton" onclick="ok();"><span><span><span class="add">确定</span></span></span></button> 
        <button type="button" id="btnCancel" class="sexybutton" onclick="cancel();"><span><span><span class="cancel">取消</span></span></span></button>           
    </div>--%>
    <div>
        <%--<span>名字后面带有的<span class='demoFirstPageButtonStyle'></span><span class='demoPrevPageButtonStyle'></span><span class='demoNextPageButtonStyle'></span><span class='demoLastPageButtonStyle'></span><br/>由于数据量比较大采取分页显示</span>--%>
        <%--<span>操作说明:</span>--%>
    </div>
    <div>
        <%--<button type="button" id="btnGetFromRoot" class="sexybutton" style=" margin-left:10px;margin-top:5px;"><span><span><span class="select">从根节点展开</span></span></span></button> --%>
        <%--<button type="button" id="btnSearchAll" class="sexybutton" style=" margin-left:10px;margin-top:5px;"><span><span><span class="search">全局搜索</span></span></span></button>  --%>
    </div>
    <div id="divZTree" style=" border-color:Gray; border-style:dotted; border-width:1px;">
        <ul id="treeContainer" class="ztree"></ul>
    </div>
    <div id="dataEditor" style="position:absolute; float:left; z-index:999999; background-color:White; padding:20px;border-color:#3399CC; border-style:solid; border-width:2px; display:none;">
        <span>&nbsp;&nbsp;&nbsp;编目名称(必填)：</span> 
        &nbsp;<input id="dataEditor_text"/>
        <span id="dataEditor_textValidateMsg" style="color:Red;display:none;">必须填写编目名称</span><br/>
        <span style=" margin-top:5px;">允许子编目(必填)：</span>
        <input type="radio" id="dataEditor_radioA" value="1" onclick="dataEditor_radioA_click();" style=" margin-top:5px;"/><span>是</span>
        <input type="radio" id="dataEditor_radioB" value="0" checked="checked" onclick="dataEditor_radioB_click();" style=" margin-top:5px;"/><span>否</span>
        <span id="dataEditor_radiosValidateMsg" style="color:Red;display:none;margin-top:5px;" >必须选择是否允许创建子编目</span><br/>
        <button type="button" id="dataEditor_btnOK" class="sexybutton" style=" margin-left:30px;margin-top:5px;"><span><span><span class="add">确定</span></span></span></button> 
        <button type="button" id="dataEditor_btnCancel" class="sexybutton" onclick="dataEditor_cancel_click();" style=" margin-left:15px;margin-top:5px;"><span><span><span class="cancel">取消</span></span></span></button>  
    </div>
    <div id="divOverlay" class="divOverlay"></div>
    <div id="divOverlay2" class="divOverlay2"></div>
    <div id="searchBox" style=" border-color:#3399CC; border-width:1px; border-style:solid; position:absolute; display:none; background-color:White; padding:2px;">
        <select style="height:auto;" id="selectLevel">
            <option value="1">&nbsp;直接子节点&nbsp;</option>
            <option value="all">&nbsp;所有子节点&nbsp;</option>
        </select>
        <select style="height:auto;" id="selectWhere">
            <option value="allName">&nbsp;精确编目名称&nbsp;</option>
            <option value="likeName">&nbsp;模糊编目名称&nbsp;</option>
        </select>
        <input id="searchText" type="text" style="height:auto;"/>
        <span class="searchSpanInSearchBox" title="搜索" id="searchBox_search"></span>
        <span class="cancelSpanInSearchBox" title="取消" onclick="searchBox_cancel_click();"></span>
    </div>
</asp:Content>

